import request from '@/libs/request'

export const login = (data) => {
  return request({
    url: '/admin/login',
    method: 'post',
    params: data
  })
}

export const logout = () => {
  return request({
    url: '/admin/logout',
    method: 'post'
  })
}
const baseUserApiPath = '/admin/user/'

export const getInfo = (token) => {
  return request({
    url: baseUserApiPath + 'info',
    method: 'get',
    params: { token }
  })
}

export const dataGrid = (data) => {
  return request({
    url: baseUserApiPath + 'dataGrid',
    method: 'post',
    data: request.obj2FormData(data)
  })
}

export const deleteUser = (userId) => {
  return request({
    url: baseUserApiPath + 'delete',
    method: 'delete',
    params: { id: userId }
  })
}

export const addUser = (data) => {
  return request({
    url: baseUserApiPath + 'add',
    method: 'put',
    data: request.obj2FormData(data)
  })
}

export const getUesrById = (params) => {
  return request({
    url: baseUserApiPath + 'getUesrById',
    method: 'get',
    params
  })
}

export const editUser = (data) => {
  return request({
    url: baseUserApiPath + 'edit',
    method: 'post',
    data: request.obj2FormData(data)
  })
}

export const editCurrentUser = (data) => {
  return request({
    url: baseUserApiPath + 'editCurrent',
    method: 'post',
    data: request.obj2FormData(data)
  })
}

export const updatePwd = (params) => {
  return request({
    url: baseUserApiPath + 'editUserPwd',
    method: 'post',
    params
  })
}
